<template>
  <div>
    <div @keyup.enter="getData()">
      <el-form :inline="true">
        <el-form-item>
          <el-input v-model="params.customer_name" placeholder="项目名称查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="params.corp_name"
            placeholder="负责人查询"
            :clearable="true"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <select-address
            v-model="params.address_code"
            clearable
            placeholder="地址查询"
            :auto-top="true"
            @change="getData()"
          ></select-address>
        </el-form-item>
        <el-form-item>
          <el-button @click="getData()">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="exportExcel(fileName)" :loading="exportLoading">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <c-table
      border
      v-loading="loading"
      :stripe="false"
      :columns="tableColumns"
      :data="tableData"
      :height="dialogHeight"
    ></c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <register-edit-reply-dialog
      :visible.sync="reportVisible"
      @success="handleEditSuccess"
      :viewMode="isViewMode"
      :relatedData="relatedData"
    ></register-edit-reply-dialog>

    <register-province-dialog
      :visible.sync="replyVisible"
      :view-mode="isViewMode"
      @success="handleEditSuccess"
      :query-id="replyRelatedId"
    ></register-province-dialog>
  </div>
</template>
<script>
import { enumGuatype } from '@/credit/plugins/enumTown'
import taskTableMixin from '@/credit/mixin/task/taskTable'
import RegisterEditReplyDialog from '@/credit/views/county/mission/RegisterEditReplyDialog'
import RegisterProvinceDialog from '@/credit/views/county/unionProvince/components/replayRegister/RegisterEditReplyDialog'

import SelectAddress from '@/components/select/SelectAddress'
export default {
  components: {
    RegisterEditReplyDialog,
    SelectAddress,
    RegisterProvinceDialog,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      enumGuatype,
      order: {},
      params: {
        index: 1,
        size: 10,
      },
      // tableName: 'customer_related',
      tableData: [],
      tableColumns: [
        {
          attrs: { label: '主体名称', prop: 'customer_name', minWidth: 135 },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '地址', prop: 'address', minWidth: 135 } },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
        { attrs: { label: '项目类型', prop: 'project_type', align: 'center' } },
        {
          attrs: { label: '操作', align: 'center', width: 100 },
          operations: [
            { name: '登记', event: this.handleEdit, ifRender: row => +row.task_status === 0 },
            { name: '查看', event: this.handleEdit, ifRender: row => +row.task_status === 1 },
          ],
        },
      ],

      reportVisible: false,
      isViewMode: false,
      relatedData: {},
      replyVisible: false,
      replyRelatedId: '',
    }
  },
  computed: {
    fileName() {
      if (+this.status === 0) {
        return '未登记项目'
      } else {
        return '已登记项目'
      }
    },
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    dataAdapter(item) {
      item.project_type = enumGuatype[+item.gua_type] || '-'
      return item
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
    handleEdit(row) {
      this.isViewMode = +row.task_status === 1
      if (+row.gua_type === 2) {
        this.relatedData = { ...row }
        this.reportVisible = true
      } else {
        this.replyVisible = true
        this.replyRelatedId = row.customer_related_id
      }
    },
    handleEditSuccess() {
      this.$store.dispatch('getMyTaskCount')
      this.$emit('success', true)
    },
  },
}
</script>
<style lang="scss" scoped></style>
